package com.situ.mall.web.controller;

import com.situ.mall.common.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author yangkx
 * @create 2023-09-18-13:48
 */
@Controller
@RequestMapping("/")
public class IndexController {

    @Autowired
    private IProductService productService;

    //请求转发带数据到页面
    //只要一访问主页就执行
    @GetMapping("/")
    public String index(Model model){
        //查数据，并给查出来的数据起个名，带到页面上
        model.addAttribute("products", productService.indexProducts(1));
        //return+字符串就是转发到页面
        return "index";
    }

}
